package jianzhi

func exchange(nums []int) []int {
	l1 := []int{}
	l2 := []int{}
	res := []int{}

	for _, v := range nums {
		if v%2 == 1 {
			l1 = append(l1, v)
		} else {
			l2 = append(l2, v)
		}
	}

	res = append(res, l1...)
	res = append(res, l2...)

	return res
}

func exchange2(nums []int) []int {
	left := 0
	right := len(nums) - 1

	for right > left {
		for nums[left]%2 != 0 && right > left {
			left++
		}

		for nums[right]%2 == 0 && right > left {
			right--
		}

		nums[right], nums[left] = nums[left], nums[right]

	}

	return nums

}
